package javase0828;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * socket服务端
 */
public class Demo02 {
    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket socket = serverSocket.accept();
        InputStream is = socket.getInputStream();
        OutputStream oos = null;
        oos = socket.getOutputStream();

        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader bufferedReader = new BufferedReader(isr);

        String s = bufferedReader.readLine();
        System.out.println(s);

        String ss = "helloServe";
        oos.write(ss.getBytes());
        oos.flush();
        oos.close();

        bufferedReader.close();
        isr.close();
        is.close();

        socket.close();
        serverSocket.close();
    }
}
